from math import sqrt
class Link:
    empty=()
    def __init__(self,first,rest=empty):
        assert rest is Link.empty or isinstance(rest,Link)
        self.first=first
        self.rest=rest
    def __repr__(self):
        if self.rest:
            rest_repr = ', ' + repr(self.rest)
        else:
            rest_repr = ''
        return 'Link(' + repr(self.first) + rest_repr + ')'

    def __str__(self):
        string = '<'
        while self.rest is not Link.empty:
            string += str(self.first) + ' '
            self = self.rest
        return string + str(self.first) + '>'



square, odd = lambda x: x * x, lambda x: x % 2 == 1
def range_link(start, end):
    """Return a Link containing consecutive integers from start to end.

    >>> range_link(3, 6)
    Link(3, Link(4, Link(5)))
    """
    if start >= end:
        return Link.empty
    else:
        return Link(start, range_link(start + 1, end))


def map_link(f, s):
    """Return a Link that contains f(x) for each x in Link s.

    >>> map_link(square, range_link(3, 6))
    Link(9, Link(16, Link(25)))
    """
    if s is Link.empty:
        return s
    else:
        return Link(f(s.first), map_link(f, s.rest))


def filter_link(f, s):
    """Return a Link that contains only the elements x of Link s for which f(x)
    is a true value.

    >>> filter_link(odd, range_link(3, 6))
    Link(3, Link(5))
    """
    if s is Link.empty:
        return s
    filtered_rest = filter_link(f, s.rest)
    if f(s.first):
        return Link(s.first, filtered_rest)
    else:
        return filtered_rest

        
# class Point(object):

#     def __init__(self, x=0, y=0):

#         self.x = x

#         self.y = y

#     def test(self, other):

#         print('this %f' % (sqrt((self.x - other.x)**2 +(self.y - other.y)**2)))
        
# if __name__ == "__main__":
#     x=float(input("横坐标"))
#     y=float(input("纵坐标"))
#     a = Point(x, y)

#     b = Point(3, 4)

#     a.test(b)
# square, odd = lambda x: x * x, lambda x: x % 2 == 1
# list(map(square, filter(odd, range(1, 6))))  # [1, 9, 25]
def add(s,v):
    assert s is not Link.empty and isinstance(s,Link)
    if s.first>v:
        s.rest=Link(s.first,s.rest)
        s.first=v
    elif s.first<v and s.rest is Link.empty:
        s.rest=Link(v)
    elif s.first<v:
        add(s.rest,v) #cannot use "return"
    return s 

        